package com.ws.ssmzongjie3.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.net.httpserver.Authenticator;
import com.ws.ssmzongjie3.bean.Links;
import com.ws.ssmzongjie3.bean.ProVo;
import com.ws.ssmzongjie3.service.LinksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/links")
public class LinksController {
    @Autowired
    private LinksService linksService;
    @RequestMapping("/list")
    public String select(Model model, ProVo proVo, Links links){
        System.out.println("links:"+links);

        PageHelper pageHelper = new PageHelper();//分页帮助类
        pageHelper.startPage(proVo.getCurrentPage(),proVo.getPageSize());//分页   每页条数

        List<Links> links1 = linksService.listLinks(links);
        PageInfo pageInfo = new PageInfo(links1);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("links",links);

        return "/WEB-INF/admin/link/list";
    }
    @RequestMapping("/add")
    public String add() {
        return "/WEB-INF/admin/link/add";
    }
    @RequestMapping("/insert")
    public String insert(Links links) {
        linksService.insertLinks(links);
        return "redirect:/links/list";
    }
    @RequestMapping("/delete")
    public String delete(Links links) {
        int i = linksService.deleteById(links.getLinks_id());
        return "redirect:/links/list";
    }

    @RequestMapping("/huixian")
    public String huixian(Links links,Model model) {
        Links links2 = linksService.getById(links.getLinks_id());
        model.addAttribute("links",links2);
        return "/WEB-INF/admin/link/update";
    }


    @RequestMapping("/update")
    public String update(Links links) {
        linksService.updateById(links);
        return "redirect:/links/list";
    }
}